import java.math.BigInteger;
import java.util.Stack;

public class Leet2 {
    public static void main(String[] args) {

    }
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
//        Stack<Integer> num1 = new Stack<>();
//        Stack<Integer> num2 = new Stack<>();
        StringBuilder num1 = new StringBuilder();
        StringBuilder num2 = new StringBuilder();
        while (l1!=null){
            num1.append(l1.val);
            l1 = l1.next;
        }
        while (l2!=null){
            num2.append(l2.val);
            l2 = l2.next;
        }
        num1.reverse();
        num2.reverse();

        char[] re = new BigInteger(num1.toString()).add(new BigInteger(num2.toString())).toString().toCharArray();
        ListNode h = new ListNode();
        ListNode now = h;
        for (int i = re.length-1; i >=0; i--) {
            now.val = Integer.parseInt(String.valueOf(re[i]));
            if (i!=0)
            now.next = new ListNode();
            now = now.next;
        }
        return h;
    }
}
